package com.lagou.service.impl;

import com.lagou.service.HelloService;
import org.apache.dubbo.config.annotation.Service;
import org.apache.dubbo.rpc.RpcContext;

import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;

@Service
public class HelloServiceImpl implements HelloService {
    
    @Override
    public String sayHello(String name, int timeToWait) {
        System.out.println("server1:"+RpcContext.getContext().getAttachments().get("ip"));
        return "hello:"+name;
    }
    
    @Override
    public String methodA(String name, int timeToWait) throws InterruptedException {

        TimeUnit.MILLISECONDS.sleep(ThreadLocalRandom.current().nextInt(100));
        return "hello methodA:"+name;
    }
    
    @Override
    public String methodB(String name, int timeToWait) throws InterruptedException {
        TimeUnit.MILLISECONDS.sleep(ThreadLocalRandom.current().nextInt(100));
        return "hello methodB:"+name;
    }
    
    @Override
    public String methodC(String name, int timeToWait) throws InterruptedException {
        TimeUnit.MILLISECONDS.sleep(ThreadLocalRandom.current().nextInt(100));
        return "hello methodC:"+name;
    }
}
